package com.sc.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sc.domain.House;
import com.sc.dto.HousePageDto;
import com.sc.mapper.HouseMapper;
import com.sc.service.HouseService;
import com.sc.vo.HousePageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HouseServiceImpl implements HouseService {
    @Autowired
    private HouseMapper houseMapper;

    @Override
    public boolean add(House house) {
        if (house.getStatus()==null){
            house.setStatus("闲置");
        }
        return houseMapper.add(house);
    }

    @Override
    public boolean deleteHouse(Integer id) {
        return houseMapper.deleteHouse(id);
    }

    @Override
    public boolean updateHouse(House house) {
        return houseMapper.updateHouse(house);
    }

    @Override
    public House selectById(Integer id) {
        return houseMapper.selectById(id);
    }

    @Override
    public  Map<String,Object> pageQuery(HousePageDto housePageDto) {
        PageHelper.startPage(housePageDto.getPage(), housePageDto.getPageSize());
        Page<HousePageVo> pageInfo = houseMapper.pageQuery(housePageDto);
        Map<String,Object> map=new HashMap<>();
        map.put("total",pageInfo.getTotal());
        map.put("pageSize",pageInfo.getPageSize());
        map.put("pageNumber",pageInfo.getPageNum());
        map.put("data",pageInfo.getResult());
        return map;
    }

    @Override
    public boolean deleteHouseByIds(List<Integer> ids) {
        return houseMapper.deleteHouseByIds(ids);
    }
}

